﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
#if !NETCOREAPP
using System.Web;
using System.Web.Mvc;
using System.Web.WebPages;
#endif

#if NETCOREAPP
using Microsoft.AspNetCore.Mvc.Rendering;
using Kugar.Core.Web;
#endif

using Kugar.MVC.MobileUI.WeUI.Helpers;

namespace Kugar.MVC.MobileUI.WeUI.PageControls.PageForm
{
    public class PageForm_Counter:PageForm_FieldBase
    {
        private string _preText = "";
        private int _value = 0;
        private int? _max = null;
        private int? _min = null;

        public PageForm_Counter(ViewContext viewContext) : base(viewContext)
        {
            this.Css("weui-cell_counter");
        }

        protected override void RenderHeader()
        {
            
        }

        protected override void RenderBody()
        {
            ViewContext.Writer.WriteLine($"<p>{_label}</p>");
        }

        public PageForm_Counter Value(int value)
        {
            _value = value;

            return this;
        }

        public PageForm_Counter CounterLabel(string label)
        {
            _preText = label;

            return this;
        }

        public PageForm_Counter Max(int? value)
        {
            _max = value;

            return this;
        }

        public PageForm_Counter Min(int? value)
        {
            _min = value;

            return this;
        }

        protected override void RenderFooter()
        {
            /*
             <span class="price">￥35.00</span>
               <div class="weui-count">
               <a class="weui-count__btn weui-count__decrease"></a>
               <input class="weui-count__number" value="1" type="number">
               <a class="weui-count__btn weui-count__increase"></a>
            </div>
             */


            ViewContext.Writer.WriteLine($"<span class=\"price\">{_preText}</span>");

            ViewContext.Writer.WriteLine($"<div class=\"weui-count\">");

            ViewContext.Writer.WriteLine($"<a class=\"weui-count__btn weui-count__decrease\"></a><input data-max=\"{_max}\" data-min=\"{_min}\" class=\"weui-count__number\" name=\"{_name}\" value=\"{_value}\" type=\"number\"><a class=\"weui-count__btn weui-count__increase\"></a>");


            ViewContext.Writer.WriteLine("</div> <!-- end weui-count -->");

            base.RenderFooter();

        }
    }
}